<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/random/mersenne_twister.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/random</a> - mersenne_twister.hpp<span style="font-size: 80%;"> (source / <a href="mersenne_twister.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">39</td>
            <td class="headerCovTableEntry">40</td>
            <td class="headerCovTableEntryHi">97.5 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /* boost random/mersenne_twister.hpp header file</a>
<span class="lineNum">       2 </span>            :  *
<span class="lineNum">       3 </span>            :  * Copyright Jens Maurer 2000-2001
<span class="lineNum">       4 </span>            :  * Copyright Steven Watanabe 2010
<span class="lineNum">       5 </span>            :  * Distributed under the Boost Software License, Version 1.0. (See
<span class="lineNum">       6 </span>            :  * accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       7 </span>            :  * http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       8 </span>            :  *
<span class="lineNum">       9 </span>            :  * See http://www.boost.org for most recent version including documentation.
<span class="lineNum">      10 </span>            :  *
<span class="lineNum">      11 </span>            :  * $Id$
<span class="lineNum">      12 </span>            :  *
<span class="lineNum">      13 </span>            :  * Revision history
<span class="lineNum">      14 </span>            :  *  2013-10-14  fixed some warnings with Wshadow (mgaunard)
<span class="lineNum">      15 </span>            :  *  2001-02-18  moved to individual header files
<span class="lineNum">      16 </span>            :  */
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #ifndef BOOST_RANDOM_MERSENNE_TWISTER_HPP
<span class="lineNum">      19 </span>            : #define BOOST_RANDOM_MERSENNE_TWISTER_HPP
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : #include &lt;iosfwd&gt;
<span class="lineNum">      22 </span>            : #include &lt;istream&gt;
<span class="lineNum">      23 </span>            : #include &lt;stdexcept&gt;
<span class="lineNum">      24 </span>            : #include &lt;boost/config.hpp&gt;
<span class="lineNum">      25 </span>            : #include &lt;boost/cstdint.hpp&gt;
<span class="lineNum">      26 </span>            : #include &lt;boost/integer/integer_mask.hpp&gt;
<span class="lineNum">      27 </span>            : #include &lt;boost/random/detail/config.hpp&gt;
<span class="lineNum">      28 </span>            : #include &lt;boost/random/detail/ptr_helper.hpp&gt;
<span class="lineNum">      29 </span>            : #include &lt;boost/random/detail/seed.hpp&gt;
<span class="lineNum">      30 </span>            : #include &lt;boost/random/detail/seed_impl.hpp&gt;
<span class="lineNum">      31 </span>            : #include &lt;boost/random/detail/generator_seed_seq.hpp&gt;
<span class="lineNum">      32 </span>            : #include &lt;boost/random/detail/polynomial.hpp&gt;
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span>            : #include &lt;boost/random/detail/disable_warnings.hpp&gt;
<span class="lineNum">      35 </span>            : 
<span class="lineNum">      36 </span>            : namespace boost {
<span class="lineNum">      37 </span>            : namespace random {
<span class="lineNum">      38 </span>            : 
<span class="lineNum">      39 </span>            : /**
<span class="lineNum">      40 </span>            :  * Instantiations of class template mersenne_twister_engine model a
<span class="lineNum">      41 </span>            :  * \pseudo_random_number_generator. It uses the algorithm described in
<span class="lineNum">      42 </span>            :  *
<span class="lineNum">      43 </span>            :  *  @blockquote
<span class="lineNum">      44 </span>            :  *  &quot;Mersenne Twister: A 623-dimensionally equidistributed uniform
<span class="lineNum">      45 </span>            :  *  pseudo-random number generator&quot;, Makoto Matsumoto and Takuji Nishimura,
<span class="lineNum">      46 </span>            :  *  ACM Transactions on Modeling and Computer Simulation: Special Issue on
<span class="lineNum">      47 </span>            :  *  Uniform Random Number Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
<span class="lineNum">      48 </span>            :  *  @endblockquote
<span class="lineNum">      49 </span>            :  *
<span class="lineNum">      50 </span>            :  * @xmlnote
<span class="lineNum">      51 </span>            :  * The boost variant has been implemented from scratch and does not
<span class="lineNum">      52 </span>            :  * derive from or use mt19937.c provided on the above WWW site. However, it
<span class="lineNum">      53 </span>            :  * was verified that both produce identical output.
<span class="lineNum">      54 </span>            :  * @endxmlnote
<span class="lineNum">      55 </span>            :  *
<span class="lineNum">      56 </span>            :  * The seeding from an integer was changed in April 2005 to address a
<span class="lineNum">      57 </span>            :  * &lt;a href=&quot;http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html&quot;&gt;weakness&lt;/a&gt;.
<span class="lineNum">      58 </span>            :  *
<span class="lineNum">      59 </span>            :  * The quality of the generator crucially depends on the choice of the
<span class="lineNum">      60 </span>            :  * parameters.  User code should employ one of the sensibly parameterized
<span class="lineNum">      61 </span>            :  * generators such as \mt19937 instead.
<span class="lineNum">      62 </span>            :  *
<span class="lineNum">      63 </span>            :  * The generator requires considerable amounts of memory for the storage of
<span class="lineNum">      64 </span>            :  * its state array. For example, \mt11213b requires about 1408 bytes and
<span class="lineNum">      65 </span>            :  * \mt19937 requires about 2496 bytes.
<span class="lineNum">      66 </span>            :  */
<span class="lineNum">      67 </span>            : template&lt;class UIntType,
<span class="lineNum">      68 </span>            :          std::size_t w, std::size_t n, std::size_t m, std::size_t r,
<span class="lineNum">      69 </span>            :          UIntType a, std::size_t u, UIntType d, std::size_t s,
<span class="lineNum">      70 </span>            :          UIntType b, std::size_t t,
<span class="lineNum">      71 </span>            :          UIntType c, std::size_t l, UIntType f&gt;
<span class="lineNum">      72 </span>            : class mersenne_twister_engine
<span class="lineNum">      73 </span>            : {
<span class="lineNum">      74 </span>            : public:
<span class="lineNum">      75 </span>            :     typedef UIntType result_type;
<span class="lineNum">      76 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, word_size = w);
<span class="lineNum">      77 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, state_size = n);
<span class="lineNum">      78 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, shift_size = m);
<span class="lineNum">      79 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, mask_bits = r);
<span class="lineNum">      80 </span>            :     BOOST_STATIC_CONSTANT(UIntType, xor_mask = a);
<span class="lineNum">      81 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, tempering_u = u);
<span class="lineNum">      82 </span>            :     BOOST_STATIC_CONSTANT(UIntType, tempering_d = d);
<span class="lineNum">      83 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, tempering_s = s);
<span class="lineNum">      84 </span>            :     BOOST_STATIC_CONSTANT(UIntType, tempering_b = b);
<span class="lineNum">      85 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, tempering_t = t);
<span class="lineNum">      86 </span>            :     BOOST_STATIC_CONSTANT(UIntType, tempering_c = c);
<span class="lineNum">      87 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, tempering_l = l);
<span class="lineNum">      88 </span>            :     BOOST_STATIC_CONSTANT(UIntType, initialization_multiplier = f);
<span class="lineNum">      89 </span>            :     BOOST_STATIC_CONSTANT(UIntType, default_seed = 5489u);
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span>            :     // backwards compatibility
<span class="lineNum">      92 </span>            :     BOOST_STATIC_CONSTANT(UIntType, parameter_a = a);
<span class="lineNum">      93 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, output_u = u);
<span class="lineNum">      94 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, output_s = s);
<span class="lineNum">      95 </span>            :     BOOST_STATIC_CONSTANT(UIntType, output_b = b);
<span class="lineNum">      96 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, output_t = t);
<span class="lineNum">      97 </span>            :     BOOST_STATIC_CONSTANT(UIntType, output_c = c);
<span class="lineNum">      98 </span>            :     BOOST_STATIC_CONSTANT(std::size_t, output_l = l);
<span class="lineNum">      99 </span>            : 
<span class="lineNum">     100 </span>            :     // old Boost.Random concept requirements
<span class="lineNum">     101 </span>            :     BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
<span class="lineNum">     102 </span>            : 
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span>            :     /**
<span class="lineNum">     105 </span>            :      * Constructs a @c mersenne_twister_engine and calls @c seed().
<span class="lineNum">     106 </span>            :      */
<span class="lineNum">     107 </span>            :     mersenne_twister_engine() { seed(); }
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span>            :     /**
<span class="lineNum">     110 </span>            :      * Constructs a @c mersenne_twister_engine and calls @c seed(value).
<span class="lineNum">     111 </span>            :      */
<span class="lineNum">     112 </span>            :     BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister_engine,
<span class="lineNum">     113 </span>            :                                                UIntType, value)
<span class="lineNum">     114 </span><span class="lineCov">          2 :     { seed(value); }</span>
<span class="lineNum">     115 </span>            :     template&lt;class It&gt; mersenne_twister_engine(It&amp; first, It last)
<span class="lineNum">     116 </span>            :     { seed(first,last); }
<span class="lineNum">     117 </span>            : 
<span class="lineNum">     118 </span>            :     /**
<span class="lineNum">     119 </span>            :      * Constructs a mersenne_twister_engine and calls @c seed(gen).
<span class="lineNum">     120 </span>            :      *
<span class="lineNum">     121 </span>            :      * @xmlnote
<span class="lineNum">     122 </span>            :      * The copy constructor will always be preferred over
<span class="lineNum">     123 </span>            :      * the templated constructor.
<span class="lineNum">     124 </span>            :      * @endxmlnote
<span class="lineNum">     125 </span>            :      */
<span class="lineNum">     126 </span>            :     BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(mersenne_twister_engine,
<span class="lineNum">     127 </span>            :                                              SeedSeq, seq)
<span class="lineNum">     128 </span>            :     { seed(seq); }
<span class="lineNum">     129 </span>            : 
<span class="lineNum">     130 </span>            :     // compiler-generated copy ctor and assignment operator are fine
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span>            :     /** Calls @c seed(default_seed). */
<span class="lineNum">     133 </span>            :     void seed() { seed(default_seed); }
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span>            :     /**
<span class="lineNum">     136 </span>            :      * Sets the state x(0) to v mod 2w. Then, iteratively,
<span class="lineNum">     137 </span>            :      * sets x(i) to
<span class="lineNum">     138 </span>            :      * (i + f * (x(i-1) xor (x(i-1) rshift w-2))) mod 2&lt;sup&gt;w&lt;/sup&gt;
<a name="139"><span class="lineNum">     139 </span>            :      * for i = 1 .. n-1. x(n) is the first value to be returned by operator().</a>
<span class="lineNum">     140 </span>            :      */
<span class="lineNum">     141 </span><span class="lineCov">          2 :     BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister_engine, UIntType, value)</span>
<span class="lineNum">     142 </span>            :     {
<span class="lineNum">     143 </span>            :         // New seeding algorithm from
<span class="lineNum">     144 </span>            :         // http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
<span class="lineNum">     145 </span>            :         // In the previous versions, MSBs of the seed affected only MSBs of the
<span class="lineNum">     146 </span>            :         // state x[].
<span class="lineNum">     147 </span>            :         const UIntType mask = (max)();
<span class="lineNum">     148 </span><span class="lineCov">          2 :         x[0] = value &amp; mask;</span>
<span class="lineNum">     149 </span><span class="lineCov">       1248 :         for (i = 1; i &lt; n; i++) {</span>
<span class="lineNum">     150 </span>            :             // See Knuth &quot;The Art of Computer Programming&quot;
<span class="lineNum">     151 </span>            :             // Vol. 2, 3rd ed., page 106
<span class="lineNum">     152 </span><span class="lineCov">       1246 :             x[i] = (f * (x[i-1] ^ (x[i-1] &gt;&gt; (w-2))) + i) &amp; mask;</span>
<span class="lineNum">     153 </span>            :         }
<span class="lineNum">     154 </span>            : 
<span class="lineNum">     155 </span><span class="lineCov">          2 :         normalize_state();</span>
<span class="lineNum">     156 </span><span class="lineCov">          2 :     }</span>
<span class="lineNum">     157 </span>            : 
<span class="lineNum">     158 </span>            :     /**
<span class="lineNum">     159 </span>            :      * Seeds a mersenne_twister_engine using values produced by seq.generate().
<span class="lineNum">     160 </span>            :      */
<span class="lineNum">     161 </span>            :     BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(mersenne_twister_engine, SeeqSeq, seq)
<span class="lineNum">     162 </span>            :     {
<span class="lineNum">     163 </span>            :         detail::seed_array_int&lt;w&gt;(seq, x);
<span class="lineNum">     164 </span>            :         i = n;
<span class="lineNum">     165 </span>            : 
<span class="lineNum">     166 </span>            :         normalize_state();
<span class="lineNum">     167 </span>            :     }
<span class="lineNum">     168 </span>            : 
<span class="lineNum">     169 </span>            :     /** Sets the state of the generator using values from an iterator range. */
<span class="lineNum">     170 </span>            :     template&lt;class It&gt;
<span class="lineNum">     171 </span>            :     void seed(It&amp; first, It last)
<span class="lineNum">     172 </span>            :     {
<span class="lineNum">     173 </span>            :         detail::fill_array_int&lt;w&gt;(first, last, x);
<span class="lineNum">     174 </span>            :         i = n;
<span class="lineNum">     175 </span>            : 
<span class="lineNum">     176 </span>            :         normalize_state();
<span class="lineNum">     177 </span>            :     }
<span class="lineNum">     178 </span>            : 
<span class="lineNum">     179 </span>            :     /** Returns the smallest value that the generator can produce. */
<span class="lineNum">     180 </span>            :     static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
<span class="lineNum">     181 </span>            :     { return 0; }
<span class="lineNum">     182 </span>            :     /** Returns the largest value that the generator can produce. */
<span class="lineNum">     183 </span>            :     static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
<span class="lineNum">     184 </span>            :     { return boost::low_bits_mask_t&lt;w&gt;::sig_bits; }
<span class="lineNum">     185 </span>            : 
<span class="lineNum">     186 </span>            :     /** Produces the next value of the generator. */
<span class="lineNum">     187 </span>            :     result_type operator()();
<span class="lineNum">     188 </span>            : 
<span class="lineNum">     189 </span>            :     /** Fills a range with random values */
<span class="lineNum">     190 </span>            :     template&lt;class Iter&gt;
<span class="lineNum">     191 </span>            :     void generate(Iter first, Iter last)
<span class="lineNum">     192 </span>            :     { detail::generate_from_int(*this, first, last); }
<span class="lineNum">     193 </span>            : 
<span class="lineNum">     194 </span>            :     /**
<span class="lineNum">     195 </span>            :      * Advances the state of the generator by @c z steps.  Equivalent to
<span class="lineNum">     196 </span>            :      *
<span class="lineNum">     197 </span>            :      * @code
<span class="lineNum">     198 </span>            :      * for(unsigned long long i = 0; i &lt; z; ++i) {
<span class="lineNum">     199 </span>            :      *     gen();
<span class="lineNum">     200 </span>            :      * }
<span class="lineNum">     201 </span>            :      * @endcode
<span class="lineNum">     202 </span>            :      */
<span class="lineNum">     203 </span>            :     void discard(boost::uintmax_t z)
<span class="lineNum">     204 </span>            :     {
<span class="lineNum">     205 </span>            : #ifndef BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD
<span class="lineNum">     206 </span>            : #define BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD 10000000
<span class="lineNum">     207 </span>            : #endif
<span class="lineNum">     208 </span>            :         if(z &gt; BOOST_RANDOM_MERSENNE_TWISTER_DISCARD_THRESHOLD) {
<span class="lineNum">     209 </span>            :             discard_many(z);
<span class="lineNum">     210 </span>            :         } else {
<span class="lineNum">     211 </span>            :             for(boost::uintmax_t j = 0; j &lt; z; ++j) {
<span class="lineNum">     212 </span>            :                 (*this)();
<span class="lineNum">     213 </span>            :             }
<span class="lineNum">     214 </span>            :         }
<span class="lineNum">     215 </span>            :     }
<span class="lineNum">     216 </span>            : 
<span class="lineNum">     217 </span>            : #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
<span class="lineNum">     218 </span>            :     /** Writes a mersenne_twister_engine to a @c std::ostream */
<span class="lineNum">     219 </span>            :     template&lt;class CharT, class Traits&gt;
<span class="lineNum">     220 </span>            :     friend std::basic_ostream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     221 </span>            :     operator&lt;&lt;(std::basic_ostream&lt;CharT,Traits&gt;&amp; os,
<span class="lineNum">     222 </span>            :                const mersenne_twister_engine&amp; mt)
<span class="lineNum">     223 </span>            :     {
<span class="lineNum">     224 </span>            :         mt.print(os);
<span class="lineNum">     225 </span>            :         return os;
<span class="lineNum">     226 </span>            :     }
<span class="lineNum">     227 </span>            : 
<span class="lineNum">     228 </span>            :     /** Reads a mersenne_twister_engine from a @c std::istream */
<span class="lineNum">     229 </span>            :     template&lt;class CharT, class Traits&gt;
<span class="lineNum">     230 </span>            :     friend std::basic_istream&lt;CharT,Traits&gt;&amp;
<span class="lineNum">     231 </span>            :     operator&gt;&gt;(std::basic_istream&lt;CharT,Traits&gt;&amp; is,
<span class="lineNum">     232 </span>            :                mersenne_twister_engine&amp; mt)
<span class="lineNum">     233 </span>            :     {
<span class="lineNum">     234 </span>            :         for(std::size_t j = 0; j &lt; mt.state_size; ++j)
<span class="lineNum">     235 </span>            :             is &gt;&gt; mt.x[j] &gt;&gt; std::ws;
<span class="lineNum">     236 </span>            :         // MSVC (up to 7.1) and Borland (up to 5.64) don't handle the template
<span class="lineNum">     237 </span>            :         // value parameter &quot;n&quot; available from the class template scope, so use
<span class="lineNum">     238 </span>            :         // the static constant with the same value
<span class="lineNum">     239 </span>            :         mt.i = mt.state_size;
<span class="lineNum">     240 </span>            :         return is;
<span class="lineNum">     241 </span>            :     }
<span class="lineNum">     242 </span>            : #endif
<span class="lineNum">     243 </span>            : 
<span class="lineNum">     244 </span>            :     /**
<span class="lineNum">     245 </span>            :      * Returns true if the two generators are in the same state,
<span class="lineNum">     246 </span>            :      * and will thus produce identical sequences.
<span class="lineNum">     247 </span>            :      */
<span class="lineNum">     248 </span>            :     friend bool operator==(const mersenne_twister_engine&amp; x_,
<span class="lineNum">     249 </span>            :                            const mersenne_twister_engine&amp; y_)
<span class="lineNum">     250 </span>            :     {
<span class="lineNum">     251 </span>            :         if(x_.i &lt; y_.i) return x_.equal_imp(y_);
<span class="lineNum">     252 </span>            :         else return y_.equal_imp(x_);
<span class="lineNum">     253 </span>            :     }
<span class="lineNum">     254 </span>            : 
<span class="lineNum">     255 </span>            :     /**
<span class="lineNum">     256 </span>            :      * Returns true if the two generators are in different states.
<span class="lineNum">     257 </span>            :      */
<span class="lineNum">     258 </span>            :     friend bool operator!=(const mersenne_twister_engine&amp; x_,
<span class="lineNum">     259 </span>            :                            const mersenne_twister_engine&amp; y_)
<span class="lineNum">     260 </span>            :     { return !(x_ == y_); }
<span class="lineNum">     261 </span>            : 
<span class="lineNum">     262 </span>            : private:
<span class="lineNum">     263 </span>            :     /// \cond show_private
<span class="lineNum">     264 </span>            : 
<span class="lineNum">     265 </span>            :     void twist();
<span class="lineNum">     266 </span>            : 
<span class="lineNum">     267 </span>            :     /**
<span class="lineNum">     268 </span>            :      * Does the work of operator==.  This is in a member function
<span class="lineNum">     269 </span>            :      * for portability.  Some compilers, such as msvc 7.1 and
<span class="lineNum">     270 </span>            :      * Sun CC 5.10 can't access template parameters or static
<span class="lineNum">     271 </span>            :      * members of the class from inline friend functions.
<span class="lineNum">     272 </span>            :      *
<span class="lineNum">     273 </span>            :      * requires i &lt;= other.i
<span class="lineNum">     274 </span>            :      */
<span class="lineNum">     275 </span>            :     bool equal_imp(const mersenne_twister_engine&amp; other) const
<span class="lineNum">     276 </span>            :     {
<span class="lineNum">     277 </span>            :         UIntType back[n];
<span class="lineNum">     278 </span>            :         std::size_t offset = other.i - i;
<span class="lineNum">     279 </span>            :         for(std::size_t j = 0; j + offset &lt; n; ++j)
<span class="lineNum">     280 </span>            :             if(x[j] != other.x[j+offset])
<span class="lineNum">     281 </span>            :                 return false;
<span class="lineNum">     282 </span>            :         rewind(&amp;back[n-1], offset);
<span class="lineNum">     283 </span>            :         for(std::size_t j = 0; j &lt; offset; ++j)
<span class="lineNum">     284 </span>            :             if(back[j + n - offset] != other.x[j])
<span class="lineNum">     285 </span>            :                 return false;
<span class="lineNum">     286 </span>            :         return true;
<span class="lineNum">     287 </span>            :     }
<span class="lineNum">     288 </span>            : 
<span class="lineNum">     289 </span>            :     /**
<span class="lineNum">     290 </span>            :      * Does the work of operator&lt;&lt;.  This is in a member function
<span class="lineNum">     291 </span>            :      * for portability.
<span class="lineNum">     292 </span>            :      */
<span class="lineNum">     293 </span>            :     template&lt;class CharT, class Traits&gt;
<span class="lineNum">     294 </span>            :     void print(std::basic_ostream&lt;CharT, Traits&gt;&amp; os) const
<span class="lineNum">     295 </span>            :     {
<span class="lineNum">     296 </span>            :         UIntType data[n];
<span class="lineNum">     297 </span>            :         for(std::size_t j = 0; j &lt; i; ++j) {
<span class="lineNum">     298 </span>            :             data[j + n - i] = x[j];
<span class="lineNum">     299 </span>            :         }
<span class="lineNum">     300 </span>            :         if(i != n) {
<span class="lineNum">     301 </span>            :             rewind(&amp;data[n - i - 1], n - i);
<span class="lineNum">     302 </span>            :         }
<span class="lineNum">     303 </span>            :         os &lt;&lt; data[0];
<span class="lineNum">     304 </span>            :         for(std::size_t j = 1; j &lt; n; ++j) {
<span class="lineNum">     305 </span>            :             os &lt;&lt; ' ' &lt;&lt; data[j];
<span class="lineNum">     306 </span>            :         }
<span class="lineNum">     307 </span>            :     }
<span class="lineNum">     308 </span>            : 
<span class="lineNum">     309 </span>            :     /**
<span class="lineNum">     310 </span>            :      * Copies z elements of the state preceding x[0] into
<span class="lineNum">     311 </span>            :      * the array whose last element is last.
<span class="lineNum">     312 </span>            :      */
<span class="lineNum">     313 </span>            :     void rewind(UIntType* last, std::size_t z) const
<span class="lineNum">     314 </span>            :     {
<span class="lineNum">     315 </span>            :         const UIntType upper_mask = (~static_cast&lt;UIntType&gt;(0)) &lt;&lt; r;
<span class="lineNum">     316 </span>            :         const UIntType lower_mask = ~upper_mask;
<span class="lineNum">     317 </span>            :         UIntType y0 = x[m-1] ^ x[n-1];
<span class="lineNum">     318 </span>            :         if(y0 &amp; (static_cast&lt;UIntType&gt;(1) &lt;&lt; (w-1))) {
<span class="lineNum">     319 </span>            :             y0 = ((y0 ^ a) &lt;&lt; 1) | 1;
<span class="lineNum">     320 </span>            :         } else {
<span class="lineNum">     321 </span>            :             y0 = y0 &lt;&lt; 1;
<span class="lineNum">     322 </span>            :         }
<span class="lineNum">     323 </span>            :         for(std::size_t sz = 0; sz &lt; z; ++sz) {
<span class="lineNum">     324 </span>            :             UIntType y1 =
<span class="lineNum">     325 </span>            :                 rewind_find(last, sz, m-1) ^ rewind_find(last, sz, n-1);
<span class="lineNum">     326 </span>            :             if(y1 &amp; (static_cast&lt;UIntType&gt;(1) &lt;&lt; (w-1))) {
<span class="lineNum">     327 </span>            :                 y1 = ((y1 ^ a) &lt;&lt; 1) | 1;
<span class="lineNum">     328 </span>            :             } else {
<span class="lineNum">     329 </span>            :                 y1 = y1 &lt;&lt; 1;
<span class="lineNum">     330 </span>            :             }
<span class="lineNum">     331 </span>            :             *(last - sz) = (y0 &amp; upper_mask) | (y1 &amp; lower_mask);
<span class="lineNum">     332 </span>            :             y0 = y1;
<span class="lineNum">     333 </span>            :         }
<span class="lineNum">     334 </span>            :     }
<span class="lineNum">     335 </span>            : 
<span class="lineNum">     336 </span>            :     /**
<span class="lineNum">     337 </span>            :      * Converts an arbitrary array into a valid generator state.
<span class="lineNum">     338 </span>            :      * First we normalize x[0], so that it contains the same
<span class="lineNum">     339 </span>            :      * value we would get by running the generator forwards
<span class="lineNum">     340 </span>            :      * and then in reverse.  (The low order r bits are redundant).
<span class="lineNum">     341 </span>            :      * Then, if the state consists of all zeros, we set the
<span class="lineNum">     342 </span>            :      * high order bit of x[0] to 1.  This function only needs to
<span class="lineNum">     343 </span>            :      * be called by seed, since the state transform preserves
<a name="344"><span class="lineNum">     344 </span>            :      * this relationship.</a>
<span class="lineNum">     345 </span>            :      */
<span class="lineNum">     346 </span><span class="lineCov">          2 :     void normalize_state()</span>
<span class="lineNum">     347 </span>            :     {
<span class="lineNum">     348 </span>            :         const UIntType upper_mask = (~static_cast&lt;UIntType&gt;(0)) &lt;&lt; r;
<span class="lineNum">     349 </span>            :         const UIntType lower_mask = ~upper_mask;
<span class="lineNum">     350 </span><span class="lineCov">          2 :         UIntType y0 = x[m-1] ^ x[n-1];</span>
<span class="lineNum">     351 </span><span class="lineCov">          2 :         if(y0 &amp; (static_cast&lt;UIntType&gt;(1) &lt;&lt; (w-1))) {</span>
<span class="lineNum">     352 </span><span class="lineCov">          1 :             y0 = ((y0 ^ a) &lt;&lt; 1) | 1;</span>
<span class="lineNum">     353 </span>            :         } else {
<span class="lineNum">     354 </span><span class="lineCov">          1 :             y0 = y0 &lt;&lt; 1;</span>
<span class="lineNum">     355 </span>            :         }
<span class="lineNum">     356 </span><span class="lineCov">          2 :         x[0] = (x[0] &amp; upper_mask) | (y0 &amp; lower_mask);</span>
<span class="lineNum">     357 </span>            : 
<span class="lineNum">     358 </span>            :         // fix up the state if it's all zeroes.
<span class="lineNum">     359 </span><span class="lineCov">          2 :         for(std::size_t j = 0; j &lt; n; ++j) {</span>
<span class="lineNum">     360 </span><span class="lineCov">          2 :             if(x[j] != 0) return;</span>
<span class="lineNum">     361 </span>            :         }
<span class="lineNum">     362 </span><span class="lineNoCov">          0 :         x[0] = static_cast&lt;UIntType&gt;(1) &lt;&lt; (w-1);</span>
<span class="lineNum">     363 </span>            :     }
<span class="lineNum">     364 </span>            : 
<span class="lineNum">     365 </span>            :     /**
<span class="lineNum">     366 </span>            :      * Given a pointer to the last element of the rewind array,
<span class="lineNum">     367 </span>            :      * and the current size of the rewind array, finds an element
<span class="lineNum">     368 </span>            :      * relative to the next available slot in the rewind array.
<span class="lineNum">     369 </span>            :      */
<span class="lineNum">     370 </span>            :     UIntType
<span class="lineNum">     371 </span>            :     rewind_find(UIntType* last, std::size_t size, std::size_t j) const
<span class="lineNum">     372 </span>            :     {
<span class="lineNum">     373 </span>            :         std::size_t index = (j + n - size + n - 1) % n;
<span class="lineNum">     374 </span>            :         if(index &lt; n - size) {
<span class="lineNum">     375 </span>            :             return x[index];
<span class="lineNum">     376 </span>            :         } else {
<span class="lineNum">     377 </span>            :             return *(last - (n - 1 - index));
<span class="lineNum">     378 </span>            :         }
<span class="lineNum">     379 </span>            :     }
<span class="lineNum">     380 </span>            : 
<span class="lineNum">     381 </span>            :     /**
<span class="lineNum">     382 </span>            :      * Optimized algorithm for large jumps.
<span class="lineNum">     383 </span>            :      *
<span class="lineNum">     384 </span>            :      * Hiroshi Haramoto, Makoto Matsumoto, and Pierre L'Ecuyer. 2008.
<span class="lineNum">     385 </span>            :      * A Fast Jump Ahead Algorithm for Linear Recurrences in a Polynomial
<span class="lineNum">     386 </span>            :      * Space. In Proceedings of the 5th international conference on
<span class="lineNum">     387 </span>            :      * Sequences and Their Applications (SETA '08).
<span class="lineNum">     388 </span>            :      * DOI=10.1007/978-3-540-85912-3_26
<span class="lineNum">     389 </span>            :      */
<span class="lineNum">     390 </span>            :     void discard_many(boost::uintmax_t z)
<span class="lineNum">     391 </span>            :     {
<span class="lineNum">     392 </span>            :         // Compute the minimal polynomial, phi(t)
<span class="lineNum">     393 </span>            :         // This depends only on the transition function,
<span class="lineNum">     394 </span>            :         // which is constant.  The characteristic
<span class="lineNum">     395 </span>            :         // polynomial is the same as the minimal
<span class="lineNum">     396 </span>            :         // polynomial for a maximum period generator
<span class="lineNum">     397 </span>            :         // (which should be all specializations of
<span class="lineNum">     398 </span>            :         // mersenne_twister.)  Even if it weren't,
<span class="lineNum">     399 </span>            :         // the characteristic polynomial is guaranteed
<span class="lineNum">     400 </span>            :         // to be a multiple of the minimal polynomial,
<span class="lineNum">     401 </span>            :         // which is good enough.
<span class="lineNum">     402 </span>            :         detail::polynomial phi = get_characteristic_polynomial();
<span class="lineNum">     403 </span>            : 
<span class="lineNum">     404 </span>            :         // calculate g(t) = t^z % phi(t)
<span class="lineNum">     405 </span>            :         detail::polynomial g = mod_pow_x(z, phi);
<span class="lineNum">     406 </span>            : 
<span class="lineNum">     407 </span>            :         // h(s_0, t) = \sum_{i=0}^{2k-1}o(s_i)t^{2k-i-1}
<span class="lineNum">     408 </span>            :         detail::polynomial h;
<span class="lineNum">     409 </span>            :         const std::size_t num_bits = w*n - r;
<span class="lineNum">     410 </span>            :         for(std::size_t j = 0; j &lt; num_bits * 2; ++j) {
<span class="lineNum">     411 </span>            :             // Yes, we're advancing the generator state
<span class="lineNum">     412 </span>            :             // here, but it doesn't matter because
<span class="lineNum">     413 </span>            :             // we're going to overwrite it completely
<span class="lineNum">     414 </span>            :             // in reconstruct_state.
<span class="lineNum">     415 </span>            :             if(i &gt;= n) twist();
<span class="lineNum">     416 </span>            :             h[2*num_bits - j - 1] = x[i++] &amp; UIntType(1);
<span class="lineNum">     417 </span>            :         }
<span class="lineNum">     418 </span>            :         // g(t)h(s_0, t)
<span class="lineNum">     419 </span>            :         detail::polynomial gh = g * h;
<span class="lineNum">     420 </span>            :         detail::polynomial result;
<span class="lineNum">     421 </span>            :         for(std::size_t j = 0; j &lt;= num_bits; ++j) {
<span class="lineNum">     422 </span>            :             result[j] = gh[2*num_bits - j - 1];
<span class="lineNum">     423 </span>            :         }
<span class="lineNum">     424 </span>            :         reconstruct_state(result);
<span class="lineNum">     425 </span>            :     }
<span class="lineNum">     426 </span>            :     static detail::polynomial get_characteristic_polynomial()
<span class="lineNum">     427 </span>            :     {
<span class="lineNum">     428 </span>            :         const std::size_t num_bits = w*n - r;
<span class="lineNum">     429 </span>            :         detail::polynomial helper;
<span class="lineNum">     430 </span>            :         helper[num_bits - 1] = 1;
<span class="lineNum">     431 </span>            :         mersenne_twister_engine tmp;
<span class="lineNum">     432 </span>            :         tmp.reconstruct_state(helper);
<span class="lineNum">     433 </span>            :         // Skip the first num_bits elements, since we
<span class="lineNum">     434 </span>            :         // already know what they are.
<span class="lineNum">     435 </span>            :         for(std::size_t j = 0; j &lt; num_bits; ++j) {
<span class="lineNum">     436 </span>            :             if(tmp.i &gt;= n) tmp.twist();
<span class="lineNum">     437 </span>            :             if(j == num_bits - 1)
<span class="lineNum">     438 </span>            :                 assert((tmp.x[tmp.i] &amp; 1) == 1);
<span class="lineNum">     439 </span>            :             else
<span class="lineNum">     440 </span>            :                 assert((tmp.x[tmp.i] &amp; 1) == 0);
<span class="lineNum">     441 </span>            :             ++tmp.i;
<span class="lineNum">     442 </span>            :         }
<span class="lineNum">     443 </span>            :         detail::polynomial phi;
<span class="lineNum">     444 </span>            :         phi[num_bits] = 1;
<span class="lineNum">     445 </span>            :         detail::polynomial next_bits = tmp.as_polynomial(num_bits);
<span class="lineNum">     446 </span>            :         for(std::size_t j = 0; j &lt; num_bits; ++j) {
<span class="lineNum">     447 </span>            :             int val = next_bits[j] ^ phi[num_bits-j-1];
<span class="lineNum">     448 </span>            :             phi[num_bits-j-1] = val;
<span class="lineNum">     449 </span>            :             if(val) {
<span class="lineNum">     450 </span>            :                 for(std::size_t k = j + 1; k &lt; num_bits; ++k) {
<span class="lineNum">     451 </span>            :                     phi[num_bits-k-1] ^= next_bits[k-j-1];
<span class="lineNum">     452 </span>            :                 }
<span class="lineNum">     453 </span>            :             }
<span class="lineNum">     454 </span>            :         }
<span class="lineNum">     455 </span>            :         return phi;
<span class="lineNum">     456 </span>            :     }
<span class="lineNum">     457 </span>            :     detail::polynomial as_polynomial(std::size_t size) {
<span class="lineNum">     458 </span>            :         detail::polynomial result;
<span class="lineNum">     459 </span>            :         for(std::size_t j = 0; j &lt; size; ++j) {
<span class="lineNum">     460 </span>            :             if(i &gt;= n) twist();
<span class="lineNum">     461 </span>            :             result[j] = x[i++] &amp; UIntType(1);
<span class="lineNum">     462 </span>            :         }
<span class="lineNum">     463 </span>            :         return result;
<span class="lineNum">     464 </span>            :     }
<span class="lineNum">     465 </span>            :     void reconstruct_state(const detail::polynomial&amp; p)
<span class="lineNum">     466 </span>            :     {
<span class="lineNum">     467 </span>            :         const UIntType upper_mask = (~static_cast&lt;UIntType&gt;(0)) &lt;&lt; r;
<span class="lineNum">     468 </span>            :         const UIntType lower_mask = ~upper_mask;
<span class="lineNum">     469 </span>            :         const std::size_t num_bits = w*n - r;
<span class="lineNum">     470 </span>            :         for(std::size_t j = num_bits - n + 1; j &lt;= num_bits; ++j)
<span class="lineNum">     471 </span>            :             x[j % n] = p[j];
<span class="lineNum">     472 </span>            : 
<span class="lineNum">     473 </span>            :         UIntType y0 = 0;
<span class="lineNum">     474 </span>            :         for(std::size_t j = num_bits + 1; j &gt;= n - 1; --j) {
<span class="lineNum">     475 </span>            :             UIntType y1 = x[j % n] ^ x[(j + m) % n];
<span class="lineNum">     476 </span>            :             if(p[j - n + 1])
<span class="lineNum">     477 </span>            :                 y1 = (y1 ^ a) &lt;&lt; UIntType(1) | UIntType(1);
<span class="lineNum">     478 </span>            :             else
<span class="lineNum">     479 </span>            :                 y1 = y1 &lt;&lt; UIntType(1);
<span class="lineNum">     480 </span>            :             x[(j + 1) % n] = (y0 &amp; upper_mask) | (y1 &amp; lower_mask);
<span class="lineNum">     481 </span>            :             y0 = y1;
<span class="lineNum">     482 </span>            :         }
<span class="lineNum">     483 </span>            :         i = 0;
<span class="lineNum">     484 </span>            :     }
<span class="lineNum">     485 </span>            : 
<span class="lineNum">     486 </span>            :     /// \endcond
<span class="lineNum">     487 </span>            : 
<span class="lineNum">     488 </span>            :     // state representation: next output is o(x(i))
<span class="lineNum">     489 </span>            :     //   x[0]  ... x[k] x[k+1] ... x[n-1]   represents
<span class="lineNum">     490 </span>            :     //  x(i-k) ... x(i) x(i+1) ... x(i-k+n-1)
<span class="lineNum">     491 </span>            : 
<span class="lineNum">     492 </span>            :     UIntType x[n];
<span class="lineNum">     493 </span>            :     std::size_t i;
<span class="lineNum">     494 </span>            : };
<span class="lineNum">     495 </span>            : 
<span class="lineNum">     496 </span>            : /// \cond show_private
<span class="lineNum">     497 </span>            : 
<span class="lineNum">     498 </span>            : #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
<span class="lineNum">     499 </span>            : //  A definition is required even for integral static constants
<span class="lineNum">     500 </span>            : #define BOOST_RANDOM_MT_DEFINE_CONSTANT(type, name)                         \
<span class="lineNum">     501 </span>            : template&lt;class UIntType, std::size_t w, std::size_t n, std::size_t m,       \
<span class="lineNum">     502 </span>            :     std::size_t r, UIntType a, std::size_t u, UIntType d, std::size_t s,    \
<span class="lineNum">     503 </span>            :     UIntType b, std::size_t t, UIntType c, std::size_t l, UIntType f&gt;       \
<span class="lineNum">     504 </span>            : const type mersenne_twister_engine&lt;UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f&gt;::name
<span class="lineNum">     505 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, word_size);
<span class="lineNum">     506 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, state_size);
<span class="lineNum">     507 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, shift_size);
<span class="lineNum">     508 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, mask_bits);
<span class="lineNum">     509 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, xor_mask);
<span class="lineNum">     510 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_u);
<span class="lineNum">     511 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_d);
<span class="lineNum">     512 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_s);
<span class="lineNum">     513 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_b);
<span class="lineNum">     514 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_t);
<span class="lineNum">     515 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, tempering_c);
<span class="lineNum">     516 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, tempering_l);
<span class="lineNum">     517 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, initialization_multiplier);
<span class="lineNum">     518 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, default_seed);
<span class="lineNum">     519 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, parameter_a);
<span class="lineNum">     520 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_u );
<span class="lineNum">     521 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_s);
<span class="lineNum">     522 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_b);
<span class="lineNum">     523 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_t);
<span class="lineNum">     524 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(UIntType, output_c);
<span class="lineNum">     525 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(std::size_t, output_l);
<span class="lineNum">     526 </span>            : BOOST_RANDOM_MT_DEFINE_CONSTANT(bool, has_fixed_range);
<span class="lineNum">     527 </span>            : #undef BOOST_RANDOM_MT_DEFINE_CONSTANT
<span class="lineNum">     528 </span>            : #endif
<span class="lineNum">     529 </span>            : 
<span class="lineNum">     530 </span>            : template&lt;class UIntType,
<span class="lineNum">     531 </span>            :          std::size_t w, std::size_t n, std::size_t m, std::size_t r,
<span class="lineNum">     532 </span>            :          UIntType a, std::size_t u, UIntType d, std::size_t s,
<span class="lineNum">     533 </span>            :          UIntType b, std::size_t t,
<a name="534"><span class="lineNum">     534 </span>            :          UIntType c, std::size_t l, UIntType f&gt;</a>
<span class="lineNum">     535 </span>            : void
<span class="lineNum">     536 </span><span class="lineCov">        690 : mersenne_twister_engine&lt;UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f&gt;::twist()</span>
<span class="lineNum">     537 </span>            : {
<span class="lineNum">     538 </span>            :     const UIntType upper_mask = (~static_cast&lt;UIntType&gt;(0)) &lt;&lt; r;
<span class="lineNum">     539 </span>            :     const UIntType lower_mask = ~upper_mask;
<span class="lineNum">     540 </span>            : 
<span class="lineNum">     541 </span>            :     const std::size_t unroll_factor = 6;
<span class="lineNum">     542 </span>            :     const std::size_t unroll_extra1 = (n-m) % unroll_factor;
<span class="lineNum">     543 </span>            :     const std::size_t unroll_extra2 = (m-1) % unroll_factor;
<span class="lineNum">     544 </span>            : 
<span class="lineNum">     545 </span>            :     // split loop to avoid costly modulo operations
<span class="lineNum">     546 </span>            :     {  // extra scope for MSVC brokenness w.r.t. for scope
<span class="lineNum">     547 </span><span class="lineCov">     307050 :         for(std::size_t j = 0; j &lt; n-m-unroll_extra1; j++) {</span>
<span class="lineNum">     548 </span><span class="lineCov">     153180 :             UIntType y = (x[j] &amp; upper_mask) | (x[j+1] &amp; lower_mask);</span>
<span class="lineNum">     549 </span><span class="lineCov">     153180 :             x[j] = x[j+m] ^ (y &gt;&gt; 1) ^ ((x[j+1]&amp;1) * a);</span>
<span class="lineNum">     550 </span>            :         }
<span class="lineNum">     551 </span>            :     }
<span class="lineNum">     552 </span>            :     {
<span class="lineNum">     553 </span><span class="lineCov">       7590 :         for(std::size_t j = n-m-unroll_extra1; j &lt; n-m; j++) {</span>
<span class="lineNum">     554 </span><span class="lineCov">       3450 :             UIntType y = (x[j] &amp; upper_mask) | (x[j+1] &amp; lower_mask);</span>
<span class="lineNum">     555 </span><span class="lineCov">       3450 :             x[j] = x[j+m] ^ (y &gt;&gt; 1) ^ ((x[j+1]&amp;1) * a);</span>
<span class="lineNum">     556 </span>            :         }
<span class="lineNum">     557 </span>            :     }
<span class="lineNum">     558 </span>            :     {
<span class="lineNum">     559 </span><span class="lineCov">     547170 :         for(std::size_t j = n-m; j &lt; n-1-unroll_extra2; j++) {</span>
<span class="lineNum">     560 </span><span class="lineCov">     273240 :             UIntType y = (x[j] &amp; upper_mask) | (x[j+1] &amp; lower_mask);</span>
<span class="lineNum">     561 </span><span class="lineCov">     273240 :             x[j] = x[j-(n-m)] ^ (y &gt;&gt; 1) ^ ((x[j+1]&amp;1) * a);</span>
<span class="lineNum">     562 </span>            :         }
<span class="lineNum">     563 </span>            :     }
<span class="lineNum">     564 </span>            :     {
<span class="lineNum">     565 </span>            :         for(std::size_t j = n-1-unroll_extra2; j &lt; n-1; j++) {
<span class="lineNum">     566 </span>            :             UIntType y = (x[j] &amp; upper_mask) | (x[j+1] &amp; lower_mask);
<span class="lineNum">     567 </span>            :             x[j] = x[j-(n-m)] ^ (y &gt;&gt; 1) ^ ((x[j+1]&amp;1) * a);
<span class="lineNum">     568 </span>            :         }
<span class="lineNum">     569 </span>            :     }
<span class="lineNum">     570 </span>            :     // last iteration
<span class="lineNum">     571 </span><span class="lineCov">        690 :     UIntType y = (x[n-1] &amp; upper_mask) | (x[0] &amp; lower_mask);</span>
<span class="lineNum">     572 </span><span class="lineCov">        690 :     x[n-1] = x[m-1] ^ (y &gt;&gt; 1) ^ ((x[0]&amp;1) * a);</span>
<span class="lineNum">     573 </span><span class="lineCov">        690 :     i = 0;</span>
<span class="lineNum">     574 </span><span class="lineCov">        690 : }</span>
<span class="lineNum">     575 </span>            : /// \endcond
<span class="lineNum">     576 </span>            : 
<span class="lineNum">     577 </span>            : template&lt;class UIntType,
<span class="lineNum">     578 </span>            :          std::size_t w, std::size_t n, std::size_t m, std::size_t r,
<span class="lineNum">     579 </span>            :          UIntType a, std::size_t u, UIntType d, std::size_t s,
<span class="lineNum">     580 </span>            :          UIntType b, std::size_t t,
<span class="lineNum">     581 </span>            :          UIntType c, std::size_t l, UIntType f&gt;
<a name="582"><span class="lineNum">     582 </span>            : inline typename</a>
<span class="lineNum">     583 </span>            : mersenne_twister_engine&lt;UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f&gt;::result_type
<span class="lineNum">     584 </span><span class="lineCov">     430501 : mersenne_twister_engine&lt;UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f&gt;::operator()()</span>
<span class="lineNum">     585 </span>            : {
<span class="lineNum">     586 </span><span class="lineCov">     430501 :     if(i == n)</span>
<span class="lineNum">     587 </span><span class="lineCov">        690 :         twist();</span>
<span class="lineNum">     588 </span>            :     // Step 4
<span class="lineNum">     589 </span><span class="lineCov">     430501 :     UIntType z = x[i];</span>
<span class="lineNum">     590 </span><span class="lineCov">     430501 :     ++i;</span>
<span class="lineNum">     591 </span><span class="lineCov">     430501 :     z ^= ((z &gt;&gt; u) &amp; d);</span>
<span class="lineNum">     592 </span><span class="lineCov">     430501 :     z ^= ((z &lt;&lt; s) &amp; b);</span>
<span class="lineNum">     593 </span><span class="lineCov">     430501 :     z ^= ((z &lt;&lt; t) &amp; c);</span>
<span class="lineNum">     594 </span><span class="lineCov">     430501 :     z ^= (z &gt;&gt; l);</span>
<span class="lineNum">     595 </span><span class="lineCov">     430501 :     return z;</span>
<span class="lineNum">     596 </span>            : }
<span class="lineNum">     597 </span>            : 
<span class="lineNum">     598 </span>            : /**
<span class="lineNum">     599 </span>            :  * The specializations \mt11213b and \mt19937 are from
<span class="lineNum">     600 </span>            :  *
<span class="lineNum">     601 </span>            :  *  @blockquote
<span class="lineNum">     602 </span>            :  *  &quot;Mersenne Twister: A 623-dimensionally equidistributed
<span class="lineNum">     603 </span>            :  *  uniform pseudo-random number generator&quot;, Makoto Matsumoto
<span class="lineNum">     604 </span>            :  *  and Takuji Nishimura, ACM Transactions on Modeling and
<span class="lineNum">     605 </span>            :  *  Computer Simulation: Special Issue on Uniform Random Number
<span class="lineNum">     606 </span>            :  *  Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
<span class="lineNum">     607 </span>            :  *  @endblockquote
<span class="lineNum">     608 </span>            :  */
<span class="lineNum">     609 </span>            : typedef mersenne_twister_engine&lt;uint32_t,32,351,175,19,0xccab8ee7,
<span class="lineNum">     610 </span>            :     11,0xffffffff,7,0x31b6ab00,15,0xffe50000,17,1812433253&gt; mt11213b;
<span class="lineNum">     611 </span>            : 
<span class="lineNum">     612 </span>            : /**
<span class="lineNum">     613 </span>            :  * The specializations \mt11213b and \mt19937 are from
<span class="lineNum">     614 </span>            :  *
<span class="lineNum">     615 </span>            :  *  @blockquote
<span class="lineNum">     616 </span>            :  *  &quot;Mersenne Twister: A 623-dimensionally equidistributed
<span class="lineNum">     617 </span>            :  *  uniform pseudo-random number generator&quot;, Makoto Matsumoto
<span class="lineNum">     618 </span>            :  *  and Takuji Nishimura, ACM Transactions on Modeling and
<span class="lineNum">     619 </span>            :  *  Computer Simulation: Special Issue on Uniform Random Number
<span class="lineNum">     620 </span>            :  *  Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
<span class="lineNum">     621 </span>            :  *  @endblockquote
<span class="lineNum">     622 </span>            :  */
<span class="lineNum">     623 </span>            : typedef mersenne_twister_engine&lt;uint32_t,32,624,397,31,0x9908b0df,
<span class="lineNum">     624 </span>            :     11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253&gt; mt19937;
<span class="lineNum">     625 </span>            : 
<span class="lineNum">     626 </span>            : #if !defined(BOOST_NO_INT64_T) &amp;&amp; !defined(BOOST_NO_INTEGRAL_INT64_T)
<span class="lineNum">     627 </span>            : typedef mersenne_twister_engine&lt;uint64_t,64,312,156,31,
<span class="lineNum">     628 </span>            :     UINT64_C(0xb5026f5aa96619e9),29,UINT64_C(0x5555555555555555),17,
<span class="lineNum">     629 </span>            :     UINT64_C(0x71d67fffeda60000),37,UINT64_C(0xfff7eee000000000),43,
<span class="lineNum">     630 </span>            :     UINT64_C(6364136223846793005)&gt; mt19937_64;
<span class="lineNum">     631 </span>            : #endif
<span class="lineNum">     632 </span>            : 
<span class="lineNum">     633 </span>            : /// \cond show_deprecated
<span class="lineNum">     634 </span>            : 
<span class="lineNum">     635 </span>            : template&lt;class UIntType,
<span class="lineNum">     636 </span>            :          int w, int n, int m, int r,
<span class="lineNum">     637 </span>            :          UIntType a, int u, std::size_t s,
<span class="lineNum">     638 </span>            :          UIntType b, int t,
<span class="lineNum">     639 </span>            :          UIntType c, int l, UIntType v&gt;
<span class="lineNum">     640 </span>            : class mersenne_twister :
<span class="lineNum">     641 </span>            :     public mersenne_twister_engine&lt;UIntType,
<span class="lineNum">     642 </span>            :         w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253&gt;
<span class="lineNum">     643 </span>            : {
<span class="lineNum">     644 </span>            :     typedef mersenne_twister_engine&lt;UIntType,
<span class="lineNum">     645 </span>            :         w, n, m, r, a, u, ~(UIntType)0, s, b, t, c, l, 1812433253&gt; base_type;
<span class="lineNum">     646 </span>            : public:
<span class="lineNum">     647 </span>            :     mersenne_twister() {}
<span class="lineNum">     648 </span>            :     BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(mersenne_twister, Gen, gen)
<span class="lineNum">     649 </span>            :     { seed(gen); }
<span class="lineNum">     650 </span>            :     BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(mersenne_twister, UIntType, val)
<span class="lineNum">     651 </span>            :     { seed(val); }
<span class="lineNum">     652 </span>            :     template&lt;class It&gt;
<span class="lineNum">     653 </span>            :     mersenne_twister(It&amp; first, It last) : base_type(first, last) {}
<span class="lineNum">     654 </span>            :     void seed() { base_type::seed(); }
<span class="lineNum">     655 </span>            :     BOOST_RANDOM_DETAIL_GENERATOR_SEED(mersenne_twister, Gen, gen)
<span class="lineNum">     656 </span>            :     {
<span class="lineNum">     657 </span>            :         detail::generator_seed_seq&lt;Gen&gt; seq(gen);
<span class="lineNum">     658 </span>            :         base_type::seed(seq);
<span class="lineNum">     659 </span>            :     }
<span class="lineNum">     660 </span>            :     BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(mersenne_twister, UIntType, val)
<span class="lineNum">     661 </span>            :     { base_type::seed(val); }
<span class="lineNum">     662 </span>            :     template&lt;class It&gt;
<span class="lineNum">     663 </span>            :     void seed(It&amp; first, It last) { base_type::seed(first, last); }
<span class="lineNum">     664 </span>            : };
<span class="lineNum">     665 </span>            : 
<span class="lineNum">     666 </span>            : /// \endcond
<span class="lineNum">     667 </span>            : 
<span class="lineNum">     668 </span>            : } // namespace random
<span class="lineNum">     669 </span>            : 
<span class="lineNum">     670 </span>            : using random::mt11213b;
<span class="lineNum">     671 </span>            : using random::mt19937;
<span class="lineNum">     672 </span>            : using random::mt19937_64;
<span class="lineNum">     673 </span>            : 
<span class="lineNum">     674 </span>            : } // namespace boost
<span class="lineNum">     675 </span>            : 
<span class="lineNum">     676 </span>            : BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt11213b)
<span class="lineNum">     677 </span>            : BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937)
<span class="lineNum">     678 </span>            : BOOST_RANDOM_PTR_HELPER_SPEC(boost::mt19937_64)
<span class="lineNum">     679 </span>            : 
<span class="lineNum">     680 </span>            : #include &lt;boost/random/detail/enable_warnings.hpp&gt;
<span class="lineNum">     681 </span>            : 
<span class="lineNum">     682 </span>            : #endif // BOOST_RANDOM_MERSENNE_TWISTER_HPP
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
